/**
 * 事件触发模块 提供事件触发机制，实现模块之间的松耦合
 * 对外接口
 * on 事件侦听
 * off 事件解绑
 * trigger 事件触发
 * 调用示例
 * var event = require('sdk/event');
 * event.on('userinfo:update',function(t){
 * 		console.log('userinfo:update:::'+t);
 * 	});
 * event.trigger('userinfo:update','finish');
 */
fangimjs.define("event/event", [], function (require, exports, modules) {
    var eventspace = "sdkEvent:",//fangimjs事件命名空间
        t = {
            /*socket事件*/
            "socket:select": 1,//选择socket事件，异步实现加载
            'socket:master:set':1,
            'socket:msg:new': 1,//
            'socket:msg:change': 1,
            "socket:ui:change": 1,//uidata变化事件
            "socket:contactlist:change":1,//soket端联系人列表变化事件
            "socket:systemInfo:show":1,
            "socket:im:log":1,
            "socket:state:set":1,//自己状态改变
            "socket:userstate:logout": 1, // 登出
            "userinfo:update": 1,
            "userlist:update": 1,
            "userpanel:update": 1,
            'socket:selfdata:set':1,//设置个人信息
            "message:new": 1,
            "message:unread": 1,
            "message:history": 1,
            "assignsvrs:finish": 1,
            "switchsvrs:finish": 1,
            "loading:status": 1,
            "notice:show": 1,
            "history:empty": 1,
            /*联系人列表操作事件*/
            "action:click": 1,
            "action:change": 1,
            /*消息处理*/
            "msg:postback": 1,
            "msg:posterror": 1,
            "msg:chatWithback": 1,
            /*model层联动事件*/
            "model:contact:newMsg": 1,
            "model:contacts:change": 1,
            "model:contacts:numChange": 1,
            "model:singlecontact:change": 1,
            "model:window:change": 1,
            'model:msg:change': 1,
            'model:msg:alert': 1,
            'model:msg:receive':1,
            'model:msg:save':1,
            "model:otherContacts:change":1,
            "model:contacts:pollingState":1,//轮询联系人状态
            "model:singleContact:state":1,//单个联系人状态
            /*视图联动事件*/
            "view:contacts:add": 1,
            "view:contact:selected": 1,
            "view:window:change": 1,
            "view:newmsg:click": 1,
            "view:msg:send": 1,
            "view:msg:history": 1,
            "view:otherContacts:add":1,
            "view:otherContact:selected":1,
            "view:socket:login":1,//视图点击socket登陆操作事件
            //上传图片相关事件
            "view:image:upload": 1,
            'view:image:del': 1,
            "model:image:change": 1,
            //鼠标移入移出事件
            'view:mouse:enter': 1,
            //flash传出相关提示字符串
            'socket:msgstring:show': 1,
            // 用户被禁言
            'view:msg:frobidden': 1
        };
    var fangimjs = window.fangimjs;
    return {
        on: function (type, callback) {
            fangimjs.on(eventspace + type, callback)
        },
        off: function (type, callback) {
            fangimjs.off(eventspace + type, callback)
        },
        trigger: function (type, data) {
            t[type] && fangimjs.emit(eventspace + type, data);
        }
    }
});
